home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / textfile.swg / 0024_Linking text file w-com...pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-05-25  |  2.3 KB  |  68 lines

  1. {
  2.  
  3.      This is not related to the original topic ".. w/exe!!", but
  4.      if somebody is interested, at least I found this one a bit
  5.      excited piece of code. It makes an executable com-file from
  6.      your text and you can easily extend it to the limits you
  7.      need. Just remember that you can't call any pascal routines,
  8.      you have to write it in pure assembler. (would .80xxx have been
  9.      a better area..?) Anyway, here it is:
  10.  
  11.  --!clip!-- { Code by Kimmo Fredrikson }
  12.  
  13.   {$A+,D-,G-,I-,R-,S-}
  14.  
  15.   program txt2com;
  16.  
  17.   var
  18.     src                 : file;
  19.     dst                 : file;
  20.     buff                : array [0..2047] of byte;
  21.     bytesRead           : word;
  22.     bytesWritten        : word;
  23.     fSize               : word;
  24.  
  25.  
  26.   function t2c: word; far; assembler;
  27.   asm
  28.         jmp     @tail           { 2 bytes }
  29.  
  30.   @head:mov     ax, 0003h       { -- here starts the code part of }
  31.         int     10h             {    the txt-show-proggie.. }
  32.  
  33.         mov     cx, word ptr [@tail+100h-2]     { length of text }
  34.         lea     si, [@tail+100h-2+2]            { address of txt }
  35.  
  36.   @nxtC:mov     dl, [si]        { read a character to dl }
  37.         mov     ah, 2
  38.         int     21h
  39.         inc     si
  40.         loop    @nxtC
  41.  
  42.         mov     ax, 4c00h
  43.         int     21h             { terminate, back to dos }
  44.  
  45.   @tail:mov     ax, offset [@tail]              { length of t2c }
  46.         sub     ax, offset [@head] { this returns the length of the  }
  47.   end;                     { assembler code when called within this pascal }
  48.                                                 { program }
  49.   begin
  50.     if paramCount <> 2 then halt;
  51.     assign (src, paramStr (1));
  52.     assign (dst, paramStr (2));
  53.     reset (src, 1);
  54.     if ioResult <> 0 then halt;
  55.     if fileSize (src) > 64000 then halt;
  56.     fSize := fileSize (src) - 1;                { get rid of the ctrl-z }
  57.     reWrite (dst, 1);
  58.     if ioResult <> 0 then halt;
  59.     blockWrite (dst, pointer (longint (@t2c) + 2)^, t2c);  { the code }
  60.     blockWrite (dst, fSize, 2);                  { the length of text }
  61.     repeat
  62.       blockRead (src, buff, 2048, bytesRead);
  63.       blockWrite (dst, buff, bytesRead, bytesWritten);     { the text }
  64.     until (bytesRead = 0) or (bytesWritten <> bytesRead);
  65.     close (src);
  66.     close (dst);
  67.   end.
  68.